<?php
    $url = new Url();
    $arr_region = LoadConfig::$region;

    //var_dump($arr_region);
?>
<script type="text/javascript">

    $(document).ready(function(){

        var d = new Date();
        var time = d.getHours(); 
        if(time == 18){
            $('#mienbac').html('<a href="<?php echo Yii::app()->createUrl('home/tuongthuatmienbac')?>">XỔ SỐ MIỀN BẮC</a>');
        }
        if(time == 16){
            $('#miennam').html('<a href="<?php echo Yii::app()->createUrl('home/tuongthuatmiennam')?>">XỔ SỐ MIỀN NAM</a>');
        }
        if(time == 17){
            $('#mientrung').html('<a href="<?php echo Yii::app()->createUrl('home/tuongthuatmientrung')?>">XỔ SỐ MIỀN TRUNG</a>');
        }

        $('#mienbac').addClass('active');
        $('#trangchu').addClass('active');

        loadChat("<?=$url->createUrl('home/chat')?>");

        $(".boxCalendar").datepicker({
            dateFormat: 'yy-mm-dd',
            showOn: 'both',
            buttonImage: ' <?php echo Yii::app()->params['static_url'];?>/images/xo-so-10h-icon-LMT.png',
            buttonImageOnly: true,
        });

        $('.From').keypress(function(e){
            if(e.keyCode == 13 && !e.shiftKey){
                $(this).trigger("enterKey");
            } 
        });

        $('textarea').bind("enterKey",function(e){
            var messenger = $('.From').val();
            var url = "<?=$url->createUrl('home/chat'); ?>";
            $.ajax({
                type: "GET",
                url: url,
                global: false,
                data: {
                    messenger: messenger,
                },
                success: function(msg){  
                    if(msg==1){
                        alert('Bạn phải đăng nhập để tán gẫu');
                    }
                    if(msg==0){
                        alert('Bạn phải chưa nhập nội dung');
                    }
                    else
                    {
                        $("#CHAT").html(msg);
                        $('.From').val('');
                    }

                }
            });
        });

        $('.boxCalendar').change(function(){
            var date = $('.boxCalendar').val();
            var url = "<?=$url->createUrl('ketqua/ketquamienbac'); ?>";
            $.ajax({
                type: "GET",
                url: url,
                global: false,
                data: {
                    date: date,
                },
                success: function(msg){
                    if(msg == 1){
                        $('.XSMB, .LOTO').html('<p>Chưa có kết quả</p>')
                    }else{
                        $('.Main').html(msg);
                    }
                }
            });
        });

        var currentdate = new Date(); 
        var datetime = currentdate.getFullYear() + "/" + (currentdate.getMonth()+1)  + "/" + (currentdate.getDate()) + " 18:15:00";
        $('.count').countdown(datetime, function(event) {
            $(this).html(event.strftime('%H:%M:%S'));
        });

    });

    function messenger(){
        var messenger = $('.From').val();
        var url = "<?=$url->createUrl('home/chat'); ?>";
        $.ajax({
            type: "GET",
            url: url,
            global: false,
            data: {
                messenger: messenger,
            },
            success: function(msg){
                if(msg==1){
                    alert('Bạn phải đăng nhập để tán gẫu');
                }
                if(msg==0){
                    alert('Bạn phải chưa nhập nội dung');
                }
                else
                {
                    $("#CHAT").html(msg);
                    $('.From').val('');
                }
            }
        });
    };

    function loadChat(url){
        //alert(scroll);
        $.ajax({
            type: "POST",
            url: url,
            global: false,
            data:{
            },
            success:function(msg){
                $("#CHAT").html(msg);
            }
        });
    }

    function lastDay(){
        var date = $('.boxCalendar').val();
        var url = "<?=$url->createUrl('ketqua/ketquamienbac'); ?>";
        $.ajax({
            type: "GET",
            url: url,
            global: false,
            data: {
                last: date,
            },
            success: function(msg){
                if(msg == 1){
                    $('.XSMB, .LOTO').html('<p>Chưa có kết quả</p>')
                }else{
                    $('.Main').html(msg);
                }
            }
        });
    }

    function nextDay(){
        var date = $('.boxCalendar').val();
        var url = "<?=$url->createUrl('ketqua/ketquamienbac'); ?>";
        $.ajax({
            type: "GET",
            url: url,
            global: false,
            data: {
                next: date,
            },
            success: function(msg){
                if(msg == 1){
                    $('.XSMB, .LOTO').html('<p>Chưa có kết quả</p>')
                }else{
                    $('.Main').html(msg);
                }
            }
        });
    }

    function inketqua(region,date){
        var name = prompt("Tên đại lý");
        window.open('<?php echo $url->createUrl('home/inketqua');?>?region='+region+'&date='+date+'&name='+name);
    }

</script>

<div class="leftMain">
    <div class="menuXS">
        <ul>
            <li id="mienbac"><a href="<?php echo Yii::app()->createUrl('home/mienbac')?>"><h1>XỔ SỐ MIỀN BẮC</h1></a></li>
            <li id="mientrung"><a href="<?php echo Yii::app()->createUrl('home/mientrung')?>">XỔ SỐ MIỀN TRUNG</a></li>
            <li id="miennam"><a href="<?php echo Yii::app()->createUrl('home/miennam')?>">XỔ SỐ MIỀN NAM</a></li>
            <li id="dientoan"><a href="<?php echo Yii::app()->createUrl('home/dientoan')?>">XỔ SỐ ĐIỆN TOÁN</a></li>
        </ul>
    </div>

    <div class="XSMB">
        <div class="leftXSMB">
            <div class="titleXSMB_1">
                Kết quả sổ xố trực tiếp miền Bắc ngày <span class="red"><?php echo date('d/m/Y',strtotime($ketqua['ngay_quay'])); ?></span>
                </br>
                <p style="font-size: 12px">Đang chờ<span class="red"> KQXS Miền Bắc</span> lúc 18h15 - <?php echo date('d/m/Y'); ?>. Còn <span class="count"></span></p>
            </div>
            <div class="tableXSMB">
                <ul>
                    <li>
                        <div class="giaiXSMB">
                            <p class="red">Giải đặc biệt</p>
                        </div>
                        <div class="kqXSMB">
                            <p class="font24 red"><?php echo $ketqua['giai_dacbiet']; ?>&nbsp;</p>
                        </div>
                        <div class="both"></div>
                    </li>
                    <li>
                        <div class="giaiXSMB">
                            <p>Giải nhất</p>
                        </div>
                        <div class="kqXSMB bg_kqXSMB">
                            <p class="font18 "><?php echo $ketqua['giai_nhat']; ?>&nbsp;</p>
                        </div>
                        <div class="both"></div>
                    </li>
                    <li>
                        <div class="giaiXSMB">
                            <p>Giải nhì</p>
                        </div>
                        <div class="kqXSMB">
                            <p class="font18 "><?php echo $ketqua['giai_nhi_1']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_nhi_2']; ?></p>
                        </div>
                        <div class="both"></div>
                    </li>
                    <li>
                        <div class="giaiXSMB">
                            <p>Giải ba</p>
                        </div>
                        <div class="kqXSMB bg_kqXSMB">
                            <p class="font18 "><?php echo $ketqua['giai_ba_1']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_ba_2']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_ba_3']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_ba_4']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_ba_5']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_ba_6']; ?></p>
                        </div>
                        <div class="both"></div>
                    </li>
                    <li>
                        <div class="giaiXSMB">
                            <p>Giải tư</p>
                        </div>
                        <div class="kqXSMB">
                            <p class="font18 "><?php echo $ketqua['giai_tu_1']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_tu_2']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_tu_3']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_tu_4']; ?></p>
                        </div>
                        <div class="both"></div>
                    </li>
                    <li>
                        <div class="giaiXSMB">
                            <p>Giải năm</p>
                        </div>
                        <div class="kqXSMB bg_kqXSMB">
                            <p class="font18 "><?php echo $ketqua['giai_nam_1']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_nam_2']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_nam_3']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_nam_4']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_nam_5']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_nam_6']; ?></p>
                        </div>
                        <div class="both"></div>
                    </li>
                    <li>
                        <div class="giaiXSMB">
                            <p>Giải sáu</p>
                        </div>
                        <div class="kqXSMB">
                            <p class="font18 "><?php echo $ketqua['giai_sau_1']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_sau_2']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_sau_3']; ?></p>
                        </div>
                        <div class="both"></div>
                    </li>
                    <li>
                        <div class="giaiXSMB">
                            <p>Giải bảy</p>
                        </div>
                        <div class="kqXSMB bg_kqXSMB">
                            <p class="font18 "><?php echo $ketqua['giai_bay_1']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_bay_2']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_bay_3']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $ketqua['giai_bay_4']; ?></p>
                        </div>
                        <div class="both"></div>
                    </li>
                </ul>
            </div> 
        </div>

        <?php
            $daucuoi[1] = $ketqua['giai_dacbiet'];
            $daucuoi[2] = $ketqua['giai_nhi_1'];
            $daucuoi[3] = $ketqua['giai_nhi_2'];
            $daucuoi[4] = $ketqua['giai_ba_1'];
            $daucuoi[5] = $ketqua['giai_ba_2'];
            $daucuoi[6] = $ketqua['giai_ba_3'];
            $daucuoi[7] = $ketqua['giai_ba_4'];
            $daucuoi[8] = $ketqua['giai_ba_5'];
            $daucuoi[9] = $ketqua['giai_ba_6'];
            $daucuoi[10] = $ketqua['giai_tu_1'];
            $daucuoi[11] = $ketqua['giai_tu_2'];
            $daucuoi[12] = $ketqua['giai_tu_3'];
            $daucuoi[13] = $ketqua['giai_tu_4'];
            $daucuoi[14] = $ketqua['giai_nam_1'];
            $daucuoi[15] = $ketqua['giai_nam_2'];
            $daucuoi[16] = $ketqua['giai_nam_3'];
            $daucuoi[17] = $ketqua['giai_nam_4'];
            $daucuoi[18] = $ketqua['giai_nam_5'];
            $daucuoi[19] = $ketqua['giai_nam_6'];
            $daucuoi[20] = $ketqua['giai_sau_1'];
            $daucuoi[21] = $ketqua['giai_sau_2'];
            $daucuoi[22] = $ketqua['giai_sau_3'];
            $daucuoi[23] = $ketqua['giai_bay_1'];
            $daucuoi[24] = $ketqua['giai_bay_2'];
            $daucuoi[25] = $ketqua['giai_bay_3'];
            $daucuoi[26] = $ketqua['giai_bay_4'];
            $daucuoi[27] = $ketqua['giai_nhat'];
            //var_dump($daucuoi);
        ?>
        <div class="rightXSMB_1">
            <ul>
                <li>
                    <div class="Dau_LOTO">
                        Đầu
                    </div>
                    <div class="Duoi_LOTO">
                        <p>Đuôi</p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>0</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            &nbsp;
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==0)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>1</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==1)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>2</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==2)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>3</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==3)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>4</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==4)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>5</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==5)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>6</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==6)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>7</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==7)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>8</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==8)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
                <li>
                    <div class="Dau_LOTO">
                        <p>9</p>
                    </div>
                    <div class="Duoi_LOTO">
                        <p>
                            <?php
                                for($i=1;$i<=count($daucuoi);$i++)
                                {
                                    if(substr($daucuoi[$i],-2,1)==9)
                                    {
                                        echo substr($daucuoi[$i],-1,1)." ";
                                    }
                                }
                            ?>
                        </p>
                    </div>
                    <div class="both"></div>
                </li>
            </ul>
        </div>
        <div class="both"></div>
    </div>

    <div class="LOTO">
        <span class="red">Loto trực tiếp:</span><br />
        <?php for($i=0;$i<count($loto);$i++){?>
            <span class="boxLOTO">
                <?php echo $loto[$i]['boso'];?>
            </span>
            <?php }?>
        <div class="sms_LOTO">
            <?php echo Yii::app()->params['static_sms'];?>
        </div>
    </div>
    <div class="MXH">
        <a href="javascript:void(0);" onclick="inketqua(1,'<?php echo $ketqua['ngay_quay'];?>');" class="boxMXH bogoc">
            <img src="<?php echo Yii::app()->params['static_url'];?>images/xo-so-10h-icon-in.png" class="img_MXH" /> In vé số
        </a>
        <a href="#" class="boxMXH bogoc">
            <img src="<?php echo Yii::app()->params['static_url'];?>images/xo-so-10h-icon-in_2.png" class="img_MXH" /> Cách in vé số
        </a>
        <div id="fb-root" style="float: right;"></div>
        <script>(function(d, s, id) {
                var js, fjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id)) return;
                js = d.createElement(s); js.id = id;
                js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=670383849682676&version=v2.0";
                fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk'));
        </script>
        <div class="fb-like" data-href="http://10h.vn/" data-layout="standard" data-action="like" data-show-faces="false" data-share="true"></div>
    </div>

    <div class="CHAT">
        <div class="titleCHAT">
            Tán Gẫu
        </div>

        <div class="CHATarea">
            <textarea name="CHAT" placeholder="Nhập nội dung chat" cols="50" rows="1" class="From"></textarea>
        </div>
        <div style="padding:15px 20px 20px 0; text-align:right;">
            <a href="javascript:void(0);" id="emotion"><img src="<?php echo Yii::app()->params['static_url'];?>images/xo-so-10h-icon-yahoo.png" width="22" height="22" style="padding-right:10px;"></a>
            <a href="javascript:void(0);" onclick="loadChat('<?=$url->createUrl('home/chat')?>');"><img src="<?php echo Yii::app()->params['static_url'];?>images/Refresh.png" width="22" height="22" style="padding-right:10px;" /></a>
            <input type="button" onclick="messenger();" class="button_KQ" value="Gửi">
        </div>
        
        <div class="boxCHAT" id="CHAT"></div>
        
        <?php $this->renderPartial('boxemotion');?>
        
    </div>

</div>
<div class="rightMain">

    <div class="Box" id="boxketqua">
        <?php
            $this->renderPartial('boxketqua');
        ?>
    </div>

    <div class="Box" id="boxtienich">
        <?php $this->renderPartial('boxtienich');?>
    </div>

    <div class="Box" id="boxthongke">
        <?php $this->renderPartial('boxthongke');?>
    </div>

        </div>
        <div class="both"></div>